home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / MPW Related / DTS MPW Goodies / AddChange < prev    next >
Encoding:
Text File  |  1990-09-14  |  6.0 KB  |  231 lines  |  [TEXT/MPS ]

  1. #
  2. #    File:        AddChange
  3. #
  4. #    Contains:    script to add changes to a window
  5. #
  6. #    Usage:        AddChange window [version [commentFile]]
  7. #
  8. #    Status:        AddChange may return the following status values:
  9. #
  10. #                    0        the change was added
  11. #                    1        error
  12. #                    2        the user canceled
  13. #
  14. #                AddChange adds a change from the file, commentFile, to the window.
  15. #                The change is inserted after the Change History text. If no change history
  16. #                is found, a dialog is presented, allowing the user to add a blank header
  17. #                to the file. If no commentFile is passed, the comment field is left blank.
  18. #                The mark character is used to mark the change.
  19. #
  20. #    Written by:    Darin Adler and scott douglass
  21. #
  22. #    Copyright:    © 1988-1990 by Apple Computer, Inc., all rights reserved.
  23. #
  24. #    Change History (maintain by hand, AddChange confuses itself by editing itself):
  25. #
  26. #                  2/9/90    ags        removed EASE header conversion
  27. #                 1/23/90    dba        put in tweaks for Finder (1990 and old Change Histories)
  28. #                12/28/89    dba        don’t put the user name in Written By:
  29. #                12/27/89    dba        added a case for .aii
  30. #                12/19/89    dba        fixed the .a and .p cases (fixed in BBS by Jeff Miller)
  31. #                12/18/89    dba        made it work with upper-case extensions
  32. #                12/11/89    dba        made it work with new headers
  33. #                11/17/89    dba        use WrapCommentText
  34. #                 11/9/89    dba        stopped using LastChange marker; invented mark character
  35. #
  36. #    To Do:
  37. #
  38.  
  39. Set CaseSensitive 0
  40. Set Exit 0
  41.  
  42. # the following helps to debug until MPW sends echos to Dev:Console instead of Dev:StdErr
  43.  
  44. If {Echo}
  45.     Set somewhere "∑∑ '{Worksheet}'"
  46. Else
  47.     Set somewhere "∑ Dev:Null"
  48. End
  49.  
  50. Begin
  51.  
  52.     Set Window "{1}"                    # add change to this file (must be open window)
  53.     Set Version "{2}"                    # use this version
  54.     Set Comment "{3}"                    # get comment from this file (should not be open)
  55.  
  56.     # add <> to version number
  57.  
  58.     If "{Version}" != ""
  59.         If "{Version}" =~ /[¬∂[<]≈/
  60.             Set Version "<{Version}>"
  61.         End
  62.     End
  63.  
  64.     # get rid of obsolete marker
  65.  
  66.     Unmark LastChange "{Window}"
  67.  
  68.     # get short name of window
  69.  
  70.     If "{Window}" =~ /:*([¬:]+:*)*([¬:]+.([a-z]+)®2)®1/
  71.         Set Short "{®1}"
  72.         Set Suffix {®2}
  73.     Else If "{Window}" =~ /:*([¬:]+:*)*([¬:]+)®1/
  74.         Set Short "{®1}"
  75.         Set Suffix ""
  76.     Else
  77.         Exit 1
  78.     End
  79.  
  80.     If "{Suffix}" =~ /[chri]/        # comments for C, C headers, Rez, and .i files (used in Finder)
  81.         Set StartComment    '/*'
  82.         Set EndComment        '*/'
  83.         Set Leader            ''
  84.     Else If "{Suffix}" =~ /cp/        # comments for C++
  85.         Set StartComment    '/*'
  86.         Set EndComment        '*/'
  87.         Set Leader            ''
  88.     Else If "{Suffix}" =~ /p/        # comments for Pascal
  89.         Set StartComment    '{'
  90.         Set EndComment        '}'
  91.         Set Leader            ''
  92.     Else If "{Suffix}" =~ /a/        # comments for assembly language
  93.         Set StartComment    ';'
  94.         Set EndComment        ';'
  95.         Set Leader            ';'
  96.     Else If "{Suffix}" =~ /aii/        # comments for 6502 assembly language
  97.         Set StartComment    ';'
  98.         Set EndComment        ';'
  99.         Set Leader            ';'
  100.     Else                            # comments for shell scripts, Makefiles etc.
  101.         Set StartComment    '#'
  102.         Set EndComment        '#'
  103.         Set Leader            '#'
  104.     End
  105.  
  106.     # fix an 80’s date to be 1990 (won’t work next year)
  107.     
  108.     Find • "{Window}"
  109.     Replace /© (198[0-9])®1(≈198[0-9])«0,1» by/ '© ®1-1990 by' "{Window}"
  110.  
  111.     # find a change history
  112.  
  113.     Set Found 0
  114.  
  115.     Find • "{Window}"
  116.     Find /Change History ∂(most recent first∂):[ ∂t]*∂n{Leader}[ ∂t]*∂n/Δ "{Window}" && Set Found 1
  117.     If !{Found}
  118.         Replace /(Change History ∂(most recent first∂):[ ∂t]*∂n)/ ∂
  119.             "®1{Leader}∂n" "{Window}" && Set Found 1
  120.     End
  121.  
  122.     # if no change history was found, look for a Finder header
  123.  
  124.     If !{Found}
  125.         Replace /Change History:([ ∂t]*∂n{Leader}[ ∂t]*∂n)®1/ ∂
  126.             'Change History (most recent first):®1' "{Window}" && Set Found 1
  127.     End
  128.     If !{Found}
  129.         Replace /Change History:([ ∂t]*∂n)®1/ ∂
  130.             "Change History (most recent first):®1{Leader}∂n" "{Window}" && Set Found 1
  131.     End
  132.  
  133.     # if we still haven’t found a change history, offer to add a new one
  134.  
  135.     If !{Found}
  136.         If "{Comment}" ≠ ""
  137.             Confirm -t "I can’t find a change history in “{Short}”. Do you want to add a header?"
  138.             Set ConfirmStatus {Status}
  139.             If {ConfirmStatus} == 5                            # cancel: report this to the caller
  140.                 Exit 2
  141.             Else If {ConfirmStatus} == 4                    # no: don’t add the change
  142.                 Exit
  143.             End                                                # yes: go on with life as usual
  144.         End
  145.  
  146.         If "{Contents}" == ""
  147.             Set Contents "xxx put contents here xxx"
  148.         End
  149.  
  150.         If "{Writers}" == ""
  151.             Set Writers "xxx put writers here xxx"
  152.         End
  153.  
  154.         If "{Copyright}" == ""
  155.             If "`Date -a -d`" =~ /≈, (19[0-9][0-9])®1/
  156.                 Set Copyright "© {®1} by Apple Computer, Inc., all rights reserved."
  157.             End
  158.         End
  159.  
  160.         Find • "{Window}"
  161.         Begin
  162.             Echo "{StartComment}"
  163.             Echo "{Leader}∂tFile:∂t∂t{Short}"
  164.             Echo "{Leader}"
  165.             Echo "{Leader}∂tContains:∂t{Contents}"
  166.             Echo "{Leader}"
  167.             Echo "{Leader}∂tWritten by:∂t{Writers}"
  168.             Echo "{Leader}"
  169.             Echo "{Leader}∂tCopyright:∂t{Copyright}"
  170.             Echo "{Leader}"
  171.             Echo "{Leader}∂tChange History (most recent first):"
  172.             Echo "{Leader}"
  173.             Echo "{Leader}"
  174.             Echo "{Leader}∂tTo Do:"
  175.             Echo "{EndComment}"
  176.             Echo
  177.         End > "{Window}.§"
  178.         Find !0 "{Window}"
  179.         Find Δ¡3 "{Window}"
  180.     End
  181.  
  182.     # concoct the change line for the change history
  183.  
  184.     If "{Version}" == ""
  185.         Set Version ∂t∂t
  186.     Else
  187.         If "{Version}" =~ /?«5,»/
  188.             If "   {Version}" =~ /≈(????????)®1/
  189.                 Set Version "{®1}"
  190.             End
  191.         Else
  192.             If "   {Version}" =~ /≈(????)®1/
  193.                 Set Version "∂t{®1}"
  194.             End
  195.         End
  196.     End
  197.  
  198.     If "  `Date -d -s`" =~ /≈(????????)®1/
  199.         Set ChangeDate "{®1}"
  200.     Else
  201.         Set ChangeDate "??/??/??"
  202.     End
  203.  
  204.     If "{UserInitials}" == ""            # no initials, use user name instead
  205.         Set UserInitials ""                # in case it was not defined before
  206.         Set TrimmingName "{User}"        # use this for the loop
  207.         Loop
  208.             If "{TrimmingName}" =~ /([a-z])®1[a-z.]* (≈)®2/
  209.                 Set UserInitials {UserInitials}{®1}
  210.                 Set TrimmingName "{®2}"
  211.             Else If "{TrimmingName}" =~ /([a-z])®1[a-z.]*/
  212.                 Set UserInitials {UserInitials}{®1}
  213.                 Break
  214.             Else
  215.                 Set UserInitials "{User}∂n∂t∂t∂t∂t∂t∂t∂t"
  216.                 Break
  217.             End
  218.         End
  219.     End
  220.  
  221.     # put the comment at the top of the change history
  222.  
  223.     Begin
  224.         Echo -n "{Leader}∂t{Version}∂t{ChangeDate}∂t{UserInitials}∂t∂t"
  225.         WrapCommentText 65 "{Leader}∂t∂t∂t∂t∂t∂t∂t∂t∂t" < "{Comment}" || ∂
  226.             Echo -n "xxx put comment here xxx"
  227.         Echo
  228.     End > "{Window}.§"
  229.  
  230. End {somewhere}
  231.